//package com.moduleSys.config.mybatis;
//
///**
// * Created by czw on 2017/7/2 0002.
// */
//import com.alibaba.druid.pool.DruidDataSource;
//import com.alibaba.druid.util.StringUtils;
//import com.github.pagehelper.PageHelper;
//import com.moduleSys.config.druid.DruidDataSourceBuilder;
//import org.apache.ibatis.plugin.Interceptor;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.bind.RelaxedPropertyResolver;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.ApplicationContextException;
//import org.springframework.context.EnvironmentAware;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.env.Environment;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.PlatformTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//import org.springframework.transaction.annotation.TransactionManagementConfigurer;
//
//import javax.annotation.Resource;
//import javax.sql.DataSource;
//import java.io.IOException;
//import java.sql.SQLException;
//import java.util.Properties;
//
///**
// * Created by liangchong998 on 2016/8/18.
// */
//@Configuration
//@EnableTransactionManagement
//@MapperScan(value = "com.moduleSys.mapper")
//public class DatabaseConfiguration /*implements EnvironmentAware {*/{
//
//    private Logger logger = LoggerFactory.getLogger(DatabaseConfiguration.class);
//
//    //private Environment environment;
// /*   private RelaxedPropertyResolver propertyResolver;
//    @Override
//    public void setEnvironment(Environment environment) {
//        this.environment = environment;
//        this.propertyResolver = new RelaxedPropertyResolver(environment,"spring.datasource.");
//    }*/
//    //注册dataSource
//  /*  @Bean(initMethod = "init", destroyMethod = "close")
//    public DruidDataSource dataSource() throws SQLException {
//        if (StringUtils.isEmpty(propertyResolver.getProperty("url"))) {
//            System.out.println("Your database connection pool configuration is incorrect!"
//                    + " Please check your Spring profile, current profiles are:"
//                    + Arrays.toString(environment.getActiveProfiles()));
//            throw new ApplicationContextException(
//                    "Database connection pool is not configured correctly");
//        }
//        DruidDataSource druidDataSource = new DruidDataSource();
//        druidDataSource.setDriverClassName(propertyResolver.getProperty("driver-class-name"));
//        druidDataSource.setUrl(propertyResolver.getProperty("url"));
//        druidDataSource.setUsername(propertyResolver.getProperty("username"));
//        druidDataSource.setPassword(propertyResolver.getProperty("password"));
//        druidDataSource.setInitialSize(Integer.parseInt(propertyResolver.getProperty("initialSize")));
//        druidDataSource.setMinIdle(Integer.parseInt(propertyResolver.getProperty("minIdle")));
//        druidDataSource.setMaxActive(Integer.parseInt(propertyResolver.getProperty("maxActive")));
//        druidDataSource.setMaxWait(Integer.parseInt(propertyResolver.getProperty("maxWait")));
//        druidDataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(propertyResolver.getProperty("timeBetweenEvictionRunsMillis")));
//        druidDataSource.setMinEvictableIdleTimeMillis(Long.parseLong(propertyResolver.getProperty("minEvictableIdleTimeMillis")));
//        druidDataSource.setValidationQuery(propertyResolver.getProperty("validationQuery"));
//        druidDataSource.setTestWhileIdle(Boolean.parseBoolean(propertyResolver.getProperty("testWhileIdle")));
//        druidDataSource.setTestOnBorrow(Boolean.parseBoolean(propertyResolver.getProperty("testOnBorrow")));
//        druidDataSource.setTestOnReturn(Boolean.parseBoolean(propertyResolver.getProperty("testOnReturn")));
//        druidDataSource.setPoolPreparedStatements(Boolean.parseBoolean(propertyResolver.getProperty("poolPreparedStatements")));
//        druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(Integer.parseInt(propertyResolver.getProperty("maxPoolPreparedStatementPerConnectionSize")));
//        druidDataSource.setFilters(propertyResolver.getProperty("filters"));
//        return druidDataSource;
//    }*/
//
//
//    @Primary
//    @ConfigurationProperties("spring.datasource.druid")
//    @Bean("dataSource")
//    public DataSource dataSource(){
//        return DruidDataSourceBuilder.create().build();
//    }
//
//    @Bean
//    public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
//        logger.info("数据源 dataSource====》"+dataSource);
//        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//       /* sqlSessionFactoryBean.setDataSource(dataSource);*/
//        //mybatis分页
//   /*     PageHelper pageHelper = new PageHelper();
//        Properties props = new Properties();
//        props.setProperty("dialect", "mysql");
//        props.setProperty("reasonable", "true");
//        props.setProperty("supportMethodsArguments", "true");
//        props.setProperty("returnPageInfo", "check");
//        props.setProperty("params", "count=countSql");
//        pageHelper.setProperties(props); //添加插件
//        sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});*/
//        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
//        sqlSessionFactoryBean.setMapperLocations(resolver.getResources("com/moduleSys/mapper/*.xml"));
//        return sqlSessionFactoryBean.getObject();
//    }
//
//
///*    @Bean
//    @Primary
//    public DataSourceTransactionManager  transactionManager(@Qualifier("dataSource") DataSource dataSource) throws SQLException {
//        return new DataSourceTransactionManager(dataSource);
//    }*/
//}